<template>
    <rx-dialog @handOk="onOk" @cancel="cancel" btnalign="center" order="bottom">
        <rx-layout>
            <div slot="center" style="margin:10px">
                <div style="text-align:left;padding:5px;">
                    <a-button-group>
                        <a-button type="primary" @click="expandAll" size="small">{{i18n('transferMenu.expansionBtn','展开')}}</a-button>
                        <a-button type="primary" @click="collapseAll" size="small">{{i18n('transferMenu.putAwayBtn','收起')}}</a-button>
                    </a-button-group>
                </div>
                <rx-tree ref="rxTree" :url="treeUrl" showTreeIcon="true" :multiSelect="multiSelect"/>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>
import {RxDialog, Util, RxLayout, RxTree,App} from "@lowcode/jpaas-common-lib"


export default {
    name: "SysAppAllMenu",
    props: ["layerid","destroy","multiSelect"],
    mixins: [App],
    components: {
        RxDialog,
        RxLayout,
        RxTree
    },
    computed: {
        rxTree() {
            return this.$refs.rxTree;
        }
    },
    data() {
        return {
            treeUrl: '',
        }
    },
    created() {
        let url = "/api-system/system/core/sysMenu/selectMenus?type=manage";
        let appId = this.curApp.appId;
        if (appId) {
            url += "&appId=" + appId;
        }
        this.treeUrl = url;
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"sysMenu",key);
        },
        onOk(e) {
            var menus = this.getSelectMenu();
            if (!menus || menus.length == 0) {
                this.$message.error(this.i18n('transferMenu.selectTips','请选择菜单！'));
                e.loading = false;
                return;
            }
            Util.closeWindow(this, "ok");
        },
        cancel() {
            Util.closeWindow(this, "cancel");
        },
        collapseAll() {
            this.rxTree.collapseAll();
        },
        expandAll() {
            this.rxTree.expandAll();
        },
        getSelectMenu() {
            if(this.multiSelect){
                return this.rxTree.selectedKeys;
            }
            return this.rxTree.getCheckedNodes(true);
        }
    }
}
</script>

<style scoped>

</style>